package com.android.questions.config;

import java.util.Random;

/**
 * FileName: AnswerAdConfig
 * Author: admin
 * Date: 2021/11/25 16:11
 * Description:
 */
public class AnswerAdConfig {

    public static volatile int AD_INTERVAL = 10;        //答题弹出广告间隔

    public static volatile double REWARD_RANDOM = 0.0;  //激励视频展示概率
    public static volatile double FULLSCREEN_RANDOM = 1.0;  //全屏视频展示概率
    public static volatile double INTERSTITIAL_RANDOM = 0.0;  //激励视频展示概率

    public static final int AD_TYPE_NO = 0x00;
    public static final int AD_TYPE_REWARD = 0x01;
    public static final int AD_TYPE_FULLSCREEN = 0x02;
    public static final int AD_TYPE_INTERSTITIAL = 0x03;

    private static final int MAX_RANDOM = 100;
    private static final int MIN_RANDOM = 0;

    private static int getRandom() {
        return new Random().nextInt(MAX_RANDOM) + 1;
    }

    public static int getAdType() {
        int adType = AD_TYPE_FULLSCREEN;//默认全屏视频
        int random = getRandom();

        int reward = (int) (REWARD_RANDOM * MAX_RANDOM);
        int full = (int) (FULLSCREEN_RANDOM * MAX_RANDOM);
        int inter = (int) (INTERSTITIAL_RANDOM * MAX_RANDOM);

        if (reward == 0 && full == 0 && inter == 0) {
            adType = AD_TYPE_NO;
            return adType;
        }

        if (random >= MIN_RANDOM && random <= reward) {//激励视频
            adType = AD_TYPE_REWARD;
        } else if (random > reward && random <= (full + reward)) {//全屏视频
            adType = AD_TYPE_FULLSCREEN;
        } else if (random > (full + reward) && random <= MAX_RANDOM) {//插屏
            adType = AD_TYPE_INTERSTITIAL;
        }
        return adType;
    }

}